package com.formatos;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporter;
import net.sf.jasperreports.engine.export.JRXlsExporterParameter;

public class Util {
	
	public static void writeToOutputStream(OutputStream output , File file) throws IOException{
		InputStream inputStream = new FileInputStream(file);
		byte[] buf = new byte[1024];
		int len;
		while ((len = inputStream.read(buf)) > 0)
			output.write(buf, 0, len);
		inputStream.close();
		output.close();
	}
	
	public static File export(JRExporter jRExporter, String preFijoFileTmp) throws JRException, IOException{
		File filetmp = File.createTempFile(preFijoFileTmp, null);
		filetmp.deleteOnExit();
		jRExporter.setParameter(JRXlsExporterParameter.OUTPUT_FILE, filetmp);
		jRExporter.exportReport();
		return filetmp;
	}

}
